/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using FITHOU.DO;
/// <summary>
/// Summary description for tbl_HoiThoaiDAL
/// </summary>
namespace FITHOU.DAL
{

    public class tbl_HoiThoaiDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public tbl_HoiThoaiDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(tbl_HoiThoaiDO objtbl_HoiThoaiDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_HoiThoai_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@KichBan", SqlDbType.NText);
            Sqlparam.Value = objtbl_HoiThoaiDO.KichBan;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(tbl_HoiThoaiDO objtbl_HoiThoaiDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_HoiThoai_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objtbl_HoiThoaiDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@KichBan", SqlDbType.NText);
            Sqlparam.Value = objtbl_HoiThoaiDO.KichBan;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(tbl_HoiThoaiDO objtbl_HoiThoaiDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_HoiThoai_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objtbl_HoiThoaiDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_HoiThoai_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public tbl_HoiThoaiDO Select(tbl_HoiThoaiDO objtbl_HoiThoaiDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_HoiThoai_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objtbl_HoiThoaiDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objtbl_HoiThoaiDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["KichBan"]))
                    objtbl_HoiThoaiDO.KichBan = Convert.ToString(dr["KichBan"]);

            }
            return objtbl_HoiThoaiDO;
        }

        public tbl_HoiThoaiDO SelectRandom()
        {
            tbl_HoiThoaiDO objtbl_HoiThoaiDO = new tbl_HoiThoaiDO();
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_HoiThoai_GetByRandomPK";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objtbl_HoiThoaiDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["KichBan"]))
                    objtbl_HoiThoaiDO.KichBan = Convert.ToString(dr["KichBan"]);

            }
            return objtbl_HoiThoaiDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_HoiThoai_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrtbl_HoiThoaiDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    tbl_HoiThoaiDO objtbl_HoiThoaiDO = new tbl_HoiThoaiDO();
                    if (!Convert.IsDBNull(dr["ID"]))
                        objtbl_HoiThoaiDO.ID = Convert.ToInt32(dr["ID"]);
                    if (!Convert.IsDBNull(dr["KichBan"]))
                        objtbl_HoiThoaiDO.KichBan = Convert.ToString(dr["KichBan"]);
                    arrtbl_HoiThoaiDO.Add(objtbl_HoiThoaiDO);
                }
            }
            return arrtbl_HoiThoaiDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sptbl_HoiThoai_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
